//
// Created by vcq on 21/2/9.
//
#pragma once

#include "dbng.hpp"

struct course {
    int id;
    string name;
    string note;
};
REFLECTION(course, id, name,note)

json MGetCourse(basic_string_view<char> id) {
    string sql = "select * from `course` where 1=1 ";
    if (!id.empty()) {
        sql += "and id =";
        sql += id;
    }
    Dao dao;
    auto v = dao.query<course>(sql);
    nlohmann::json article_list,ret,item;
    for (auto &o : v) {
        item["id"] = o.id;
        item["name"] = o.name;
        item["note"] = o.note;
        article_list.push_back(item);
    }
    ret["code"] = 0;
    ret["count"] = article_list.size();
    ret["data"] = article_list;
    return ret;
}

void MAddCourse(const struct course& course1){
    Dao dao;
    dao.update_object(course1);
}
void MDeleteCourse(basic_string_view<char> id){
    MDeleteAll("course",id);
}